package com.neusoft.elmboot.controller;

import com.neusoft.elmboot.po.Admin;
import com.neusoft.elmboot.service.AdminService;
import com.neusoft.elmboot.util.APIResponse;
import com.neusoft.elmboot.util.ErrorCode;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("admin")
public class AdminController {

    @Resource
    private AdminService adminService;


    @PostMapping("/login")
    public APIResponse login(String  id,String pass) {
        Boolean ret = adminService.login(id,pass);
        return ret?APIResponse.success(true):APIResponse.error(ErrorCode.ERROR);
    }

    @PostMapping
    public APIResponse add(Admin admin) {

        Integer ret =  adminService.insert(admin);
        if (ret ==null){
            return APIResponse.error(ErrorCode.ERROR,"该商户已存在");
        }else {
            return APIResponse.success(ret);
        }
    }



}

